package com.example.music;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class MyBaseAdapter extends BaseAdapter {
    //创建歌曲的String数组和歌手图片的int数组
    public String[] name={
            "Are you lost","Mermaid","Norman fucking Rockwell"};
    public static int[] icons={
            R.raw.music_0, R.raw.music_1};

    @Override
    public int getCount(){
        return  name.length;}
    @Override
    public Object getItem(int i){
        return name[i];}
    @Override
    public long getItemId(int i){
        return i;}
        public MyBaseAdapter(Context context){
        super(context);
        }
    @Override
    public View getView(int i , View convertView, ViewGroup parent) {

        //绑定好VIew，然后绑定控件
        View view= LayoutInflater.from(getContext()).inflate(parent,false);
        TextView tv_name=view.findViewById(R.id.item_name);
        ImageView iv=view.findViewById(R.id.iv);
        //设置控件显示的内容，就是获取的歌曲名和歌手图片
        tv_name.setText(name[i]);
        iv.setImageResource(icons[i]);
        return view;
    }
}

